<template>
  <div class="block">
    <el-timeline>
      <el-timeline-item v-for="(item,index) of dataList" :key="index" :timestamp="item.createAt" placement="top">
        <el-card>
          <h4>{{ item.title }}</h4>
          <p>{{ item.content }}</p>
        </el-card>
      </el-timeline-item>
    </el-timeline>
    <el-divider v-if="hasMore" @click="loadData"><i class="el-icon-arrow-down" /></el-divider>
  </div>
</template>

<script>
import { loadUserTimeLine } from '@/api/user/userProfile'

export default {
  name: 'Timeline',
  data() {
    return {
      hasMore: true,
      startId: '',
      dataList: []
    }
  },
  created() {
    this.loadData()
  },
  methods: {
    loadData() {
      loadUserTimeLine(this.startId).then((response) => {
        if (response && response.data && response.data.length > 0) {
          for (const d of response.data) {
            this.dataList.push(d)
            this.startId = d.id
          }
        } else {
          this.hasMore = false
        }
      }, (response) => {
      })
    }
  }
}
</script>
